package com.gomtel.smartdevice.ui.dialog;

import android.content.Context;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gomtel.smartdevice.R;
import com.gomtel.smartdevice.base.WatchBaseDialog;
import com.gomtel.smartdevice.global.DataClass;
import com.gomtel.smartdevice.moudle.event.CommonEvent;
import com.gomtel.smartdevice.moudle.event.EventCode;
import com.gomtel.smartdevice.moudle.rxtools.EventBusUtil;
import com.gomtel.smartdevice.utils.SystemUtil;

import butterknife.BindView;


/**
 * Created by Administrator on 2018/3/21.
 */

public class StatusDialog extends WatchBaseDialog implements View.OnClickListener {

    private Context context;
    private int status;
    @BindView(R.id.btn_commit)
    Button btn_commit;
    @BindView(R.id.input_type)
    TextView input_type;
    @BindView(R.id.content_view)
    TextView content_view;
    @BindView(R.id.btn_cancle)
    Button btn_cancle;
    @BindView(R.id.line_center)
    View line_center;
    @BindView(R.id.img_view)
    View img_view;
    @BindView(R.id.img_down_tv_up_layout)
    RelativeLayout img_down_tv_up_layout;


    protected StatusDialog(Context context, @StyleRes int themeResId, int status) {
        super(context, themeResId);
        this.context = context;
        this.status = status;
    }

    @Override
    protected int getLayout() {
        return R.layout.dialog_status;
    }

    @Override
    protected void initClass() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        switch (status) {
            case EventCode.OPEN_BLOOD_PRESSURE_CALIBRATION:
                btn_cancle.setVisibility(View.GONE);
                line_center.setVisibility(View.GONE);
                input_type.setText(context.getString(R.string.warm_prompt));
                content_view.setText(context.getString(R.string.prompt_content));
                break;
            case EventCode.OPEN_CLEAR_CALIBRATION:
                img_view.setVisibility(View.VISIBLE);
                input_type.setVisibility(View.GONE);
                content_view.setText(context.getString(R.string.clear_calibration_content));
                break;
            case EventCode.OPEN_CLEAR_CACHE:
                input_type.setText(context.getString(R.string.clear_cache));
                content_view.setText(context.getString(R.string.clear_cache_content));
                break;
            case EventCode.TEST_IS_WRONG:
                img_view.setVisibility(View.VISIBLE);
                img_view.setBackground(context.getResources().getDrawable(R.drawable.exclamation_point));
                input_type.setVisibility(View.GONE);
                content_view.setText(context.getString(R.string.test_is_wrong));
                break;
            case EventCode.INSTRUCTIONS:
                btn_cancle.setVisibility(View.GONE);
                line_center.setVisibility(View.GONE);
                input_type.setText(context.getString(R.string.Blood_pressure_calibration));
                content_view.setVisibility(View.GONE);
                img_down_tv_up_layout.setVisibility(View.VISIBLE);
                break;
            case EventCode.UNDERWAY:
                img_view.setVisibility(View.VISIBLE);
                img_view.setBackground(context.getResources().getDrawable(R.drawable.exclamation_point));
                input_type.setVisibility(View.GONE);
                content_view.setText(context.getString(R.string.test_is_current));
                break;
            case EventCode.UNBUNDLE:
                input_type.setText(context.getString(R.string.unbundle_about));
                content_view.setText(context.getString(R.string.unbundle_content));
                break;
            case EventCode.SUCCESSFUL_UP:
                btn_cancle.setVisibility(View.GONE);
                line_center.setVisibility(View.GONE);
                img_view.setVisibility(View.VISIBLE);
                btn_commit.setText("OK");
                img_view.setBackground(context.getResources().getDrawable(R.drawable.exclamation_point));
                input_type.setVisibility(View.GONE);
                content_view.setText(context.getString(R.string.successful_up));
                break;
            case EventCode.LOGIN_OUT:
                input_type.setText(context.getString(R.string.logout));
                content_view.setText(context.getString(R.string.logout_content));
                break;
            case EventCode.APP_VERSION:
                input_type.setText(context.getString(R.string.version_up));
                content_view.setText(context.getString(R.string.version_up));
                break;
        }
    }

    @Override
    protected void initListener() {
        btn_commit.setOnClickListener(this);
        btn_cancle.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_commit:
                switch (status) {
                    case EventCode.OPEN_BLOOD_PRESSURE_CALIBRATION:
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.OPEN_BLOOD_PRESSURE_CALIBRATION));
                        break;
                    case EventCode.OPEN_CLEAR_CALIBRATION:
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.BPCSTANDARDCLEAR));
                        break;
                    case EventCode.OPEN_CLEAR_CACHE:
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.OPEN_CLEAR_CACHE));
                        break;
                    case EventCode.TEST_IS_WRONG:
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.TEST_IS_WRONG));
                        break;
                    case EventCode.INSTRUCTIONS:
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.INSTRUCTIONS));
                        break;
                    case EventCode.UNDERWAY:
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.UNDERWAY));
                        break;
                    case EventCode.UNBUNDLE:
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.UNBUNDLE));
                        DataClass.onlineStatus = false;
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.CTIONCONTENTSTATUS, "连接断开"));
                        break;
                    case EventCode.LOGIN_OUT:
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.LOGIN_OUT));
                        break;
                    case EventCode.APP_VERSION:
                        EventBusUtil.sendEvent(new CommonEvent(EventCode.APP_VERSION));
                        break;
                }
                dismiss();
                break;
            case R.id.btn_cancle:
                dismiss();
                break;
        }

    }

    @Override
    protected void onDismissListener() {
        super.onDismissListener();
        SystemUtil.windowToLight(context);
    }


}
